package com.smartleanx.module.hrm.controller.admin.employee;

import com.smartleanx.module.hrm.controller.admin.employee.certificate.EmployeeCertificateRespVO;
import com.smartleanx.module.hrm.controller.admin.employee.certificate.EmployeeCertificateSaveReqVO;
import com.smartleanx.module.hrm.service.employee.EmployeeCertificateService;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;

import javax.validation.*;
import javax.servlet.http.*;
import java.util.*;
import java.io.IOException;

import com.smartleanx.framework.common.pojo.PageParam;
import com.smartleanx.framework.common.pojo.PageResult;
import com.smartleanx.framework.common.pojo.CommonResult;
import com.smartleanx.framework.common.util.object.BeanUtils;
import static com.smartleanx.framework.common.pojo.CommonResult.success;

import com.smartleanx.framework.excel.core.util.ExcelUtils;

import com.smartleanx.framework.operatelog.core.annotations.OperateLog;
import static com.smartleanx.framework.operatelog.core.enums.OperateTypeEnum.*;

import com.smartleanx.module.hrm.dal.dataobject.employee.EmployeeCertificateDO;

@Tag(name = "管理后台 - 员工证书")
@RestController
@RequestMapping("/hrm/employee-certificate")
@Validated
public class EmployeeCertificateController {

    @Resource
    private EmployeeCertificateService employeeCertificateService;

    @PostMapping("/create")
    @Operation(summary = "创建员工证书")
    @PreAuthorize("@ss.hasAnyPermissions('hrm:employee-certificate:create','hrm:employee:update')")
    public CommonResult<Long> createEmployeeCertificate(@Valid @RequestBody EmployeeCertificateSaveReqVO createReqVO) {
        return success(employeeCertificateService.createEmployeeCertificate(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新员工证书")
    @PreAuthorize("@ss.hasAnyPermissions('hrm:employee-certificate:update','hrm:employee:update')")
    public CommonResult<Boolean> updateEmployeeCertificate(@Valid @RequestBody EmployeeCertificateSaveReqVO updateReqVO) {
        employeeCertificateService.updateEmployeeCertificate(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除员工证书")
    @Parameter(name = "id", description = "编号", required = true)
    @PreAuthorize("@ss.hasAnyPermissions('hrm:employee-certificate:delete','hrm:employee:update')")
    public CommonResult<Boolean> deleteEmployeeCertificate(@RequestParam("id") Long id) {
        employeeCertificateService.deleteEmployeeCertificate(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得员工证书")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasAnyPermissions('hrm:employee-certificate:query','hrm:employee:query')")
    public CommonResult<EmployeeCertificateRespVO> getEmployeeCertificate(@RequestParam("id") Long id) {
        EmployeeCertificateDO employeeCertificate = employeeCertificateService.getEmployeeCertificate(id);
        return success(BeanUtils.toBean(employeeCertificate, EmployeeCertificateRespVO.class));
    }

    @GetMapping("/list")
    @Operation(summary = "获得员工证书列表")
    @Parameter(name = "id", description = "员工id", required = true, example = "1024")
    @PreAuthorize("@ss.hasAnyPermissions('hrm:employee-certificate:query','hrm:employee:query')")
    public CommonResult<List<EmployeeCertificateRespVO>> getEmployeeCertificateList(@RequestParam("employeeId") Long employeeId){
        List<EmployeeCertificateDO> certificateList = employeeCertificateService.getEmployeeCertificateList(employeeId);
        return success(BeanUtils.toBean(certificateList, EmployeeCertificateRespVO.class));
    }
}
